package com.mickey.result;

/**
 * 结果封装
 * @param <T>
 */
public class Result<T> {

    private int code;
    private String msg;
    private T data;

    public Result(CodeMsg cm) {
        if (cm == null){
            return;
        }
        this.code = cm.getCode();
        this.msg = cm.getMsg();
    }

    public static <T> Result<T> sucess(T data){
        return new Result<>(data);
    }

    public static <T> Result<T> err(CodeMsg cm){
        return new Result<>(cm);
    }

    private Result(T data){
        this.code = 0;
        this.msg = "sucess";
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
